package com.un.ebs.inventory.controller;


import com.un.ebs.core.util.StringUtils;
import com.un.ebs.inventory.domain.InventoryNoteType;
import com.un.ebs.inventory.domain.InventoryNoteTypeExt;
import com.un.ebs.inventory.enums.InventoryTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.un.ebs.inventory.service.InventoryNoteTypeService;
import com.un.ebs.inventory.dto.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.un.ebs.core.util.WebResult;
import com.un.ebs.core.util.WebUtils;

import javax.annotation.Resource;
import java.util.List;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author liubo
 * @since 2020-05-23
 */
@RestController
@RequestMapping("/inventoryNoteType")
@Api(value = "inventory-note-type", tags = "")
public class InventoryNoteTypeController {

    @Resource
    private InventoryNoteTypeService service;

    @PostMapping("save")
    @ApiOperation(value = "save", notes = "修改")
    public WebResult update(@RequestBody @Validated InventoryNoteTypeUpdateDto req) {
        if (StringUtils.isNullOrEmpty(req.getId())) {
            service.add(req);
        } else {
            service.update(req);
        }
        return WebUtils.success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "getById", notes = "根据主键获取单个 InventoryNoteType")
    public WebResult getById(@PathVariable("id") String id) {
        return WebUtils.success(service.queryById(id));
    }

    @GetMapping("listByIn")
    @ApiOperation(value = "查询，所有入库类别")
    public WebResult<List<InventoryNoteTypeExt>> listByIn() {
        return WebUtils.success(service.querInType());
    }

    @GetMapping("listByMove")
    @ApiOperation(value = "查询，所有调拨或移库类别")
    public WebResult<List<InventoryNoteTypeExt>> listByMove() {
        return WebUtils.success(service.queryMoveType());
    }

    @GetMapping("listByOut")
    @ApiOperation(value = "查询，所有出库类别")
    public WebResult<List<InventoryNoteTypeExt>> listByOut() {
        return WebUtils.success(service.queryOutType());
    }

    @GetMapping("listByType")
    @ApiOperation(value = "查询，指定类别")
    public WebResult<List<InventoryNoteTypeExt>> listByType(@RequestParam(required = false) InventoryTypeEnum type) {
        return WebUtils.success(service.queryByType(type));
    }

    @PostMapping("delete/{id}")
    @ApiOperation(value = "delete", notes = "根据主键删除单个 InventoryNoteType")
    public WebResult delete(@PathVariable("id") String id) {
        service.delete(id);
        return WebUtils.success();
    }

}